package Mapper.User;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import pojo.huodongfabu;
import pojo.kechenghuanli;

import java.sql.*;

import static pojo.Mysql.*;

public class huodongMapper {

    public ObservableList<huodongfabu> fetchDataFromDatabase(int offset, int limit) {
        ObservableList<huodongfabu> data = FXCollections.observableArrayList();
        try (
                Connection connection = DriverManager.getConnection(url, user, dbPassword)) {
            String query = "SELECT * FROM huodongfabu LIMIT ?, ?";
            try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
                preparedStatement.setInt(1, offset);
                preparedStatement.setInt(2, limit);

                try (ResultSet resultSet = preparedStatement.executeQuery()) {
                    while (resultSet.next()) {
                        String name = resultSet.getString("name");
                        String id = resultSet.getString("id");
                        String createtime = resultSet.getString("createtime");
                        String neirong = resultSet.getString("neirong");

                        data.add(new huodongfabu(id, name,createtime, neirong));
                    }
                }
            }
        } catch (
                SQLException e) {
            e.printStackTrace();
        }

        return data;
    }
}
